#define _CRT_SECURE_NO_WARNINGS 1

#include"stack.h"

void STinit(st* p)
{
	p->a = NULL;
	p->capicity = 0;
	p->top = 0;
}

void STDestory(st* p)
{
	//assert(!STEmpty(p));
	
	free(p->a);
	p->capicity = 0;
	p->top = 0;
}


void STPush(st* p, STDateType x)
{
	if (p->capicity == p->top)
	{
		int newnode = p->top == 0 ? 4 : p->capicity * 2;
		STDateType* tmp = realloc(p->a, newnode * sizeof(STDateType));
		if (tmp == NULL)
		{
			perror("malloc file");
			return;
		}
		p->a = tmp;
		p->capicity = newnode;
	}
	p->a[p->top++] = x;
}


STDateType STTop(st* p)
{
	assert(!STEmpty(p));
	return p->a[p->top-1];
}

bool STEmpty(st* p)
{
	return p->top == 0 ;
}


int STSize(st* p)
{
	return p->top;
}


void StackPop(st* p)
{
	assert(!STEmpty(p));
	p->top--;
}